<?php
    session_start();
	require_once 'config.php' ;

    function getPassword($user, $pw) {
        global $DB, $table_prefix;
        $passwd = $DB->GetOne("SELECT `user_pass` from `${table_prefix}user` where `user_name` = ?", array($user));
        return $passwd;
    }
    
    function getIdForUser($user) {
        global $DB, $table_prefix;
        $passwd = $DB->GetOne("SELECT `user_id` from `${table_prefix}user` where `user_name` = ?", array($user));
        return $passwd;
    }

    if(isset($_POST['submit'])) {
       $pass=getPassword($_POST['username'],$_POST['password']);
  
       if($pass== md5($_POST['password']))
     {
         $_SESSION['logged'] = true;
         $_SESSION['username'] = $_POST['username'];
         $_SESSION["userid"] = getIdForUser($_POST["username"]);
         header('Location: table.php');	
        exit;
       }
   else
   { 
         header('Location: Login.html');	
   }
}   
?>
 
